﻿using System;
using System.Collections.Generic;
using JStore.Core.Dtos;
using JStore.Core.Entities;
using JStore.Data.Daos;
using SpeadFrm.MvcPager;

namespace JStore.Tasks
{
    /// <summary>
    ///
    /// </summary>
    public class MoneyLogTask
    {
        private readonly UserInfoDao _userInfoDao = new UserInfoDao();
        private readonly MoneyLogDao _moneyLogDao = new MoneyLogDao();

        public PagedList<MoneyLog> GetPagedList(string userName,string sourceUserName, int? moneyType, int pageIndex, int pageSize)
        {
            return _moneyLogDao.GetPagedList(userName,sourceUserName, moneyType, pageIndex, pageSize);
        }

        public void Pass(string operUserName, int id)
        {
            var userInfo = _userInfoDao.GetByUserName(operUserName);
            var info = _moneyLogDao.GetById(id);

            if (userInfo == null || info == null) return;

            info.OperUserId = userInfo.UserId;
            info.OperUserName = userInfo.UserName;
            info.ModifyTime = DateTime.Now;
            info.IsSend = true;
            _moneyLogDao.Update(info);
        }

        public decimal GetSum(DateTime startDate, DateTime endDate)
        {
            return _moneyLogDao.GetSum(startDate, endDate);
        }

         
    }
}

